package com.vict.bean.pay.vo;

import com.alibaba.fastjson.annotation.JSONField;
import com.vict.framework.fastjsonserializer.*;
import com.vict.framework.pay.entity.PayOrder;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.math.BigDecimal;
import java.sql.Timestamp;
import java.util.Optional;

@Data
public class PayOrderVO {

    @JSONField(serialize = false, deserialize = false)
    private PayOrder payOrder;

    @ApiModelProperty(value="payDtoId")
    public String getPayDtoId() {
        return Optional.ofNullable(payOrder).map(o-> o.getPayDtoId()).map(o-> o.trim())
                .filter(o-> !o.equals("")).orElse(null);
    }

    @ApiModelProperty(value="金额")
    @JSONField(serializeUsing = DecimalSerializer.class, deserializeUsing = DecimalDeserializer.class)
    public BigDecimal getMoney() {
        return Optional.ofNullable(payOrder).map(o-> o.getMoney())
                .map(o-> o.setScale(2, BigDecimal.ROUND_FLOOR)).orElse(null);
    }

    @ApiModelProperty(value="支付状态")
    @JSONField(serializeUsing = EnumSerializer.class, deserializeUsing = EnumDeserializer.class)
    public PayOrder.PayStatus getPayStatus() {
        return Optional.ofNullable(payOrder).map(o-> o.getPayStatus()).orElse(null);
    }

    @ApiModelProperty(value="支付方式")
    @JSONField(serializeUsing = EnumSerializer.class, deserializeUsing = EnumDeserializer.class)
    public PayOrder.PayType getPayType() {
        return Optional.ofNullable(payOrder).map(o-> o.getPayType()).orElse(null);
    }

    @ApiModelProperty(value="创建时间")
    @JSONField(serializeUsing = TimestampSerializer.class, deserializeUsing = TimestampDeserializer.class)
    public Timestamp getStartTime() {
        return Optional.ofNullable(payOrder).map(o-> o.getStartTime()).orElse(null);
    }

    @ApiModelProperty(value="过期时间")
    @JSONField(serializeUsing = TimestampSerializer.class, deserializeUsing = TimestampDeserializer.class)
    public Timestamp getOverTime() {
        return Optional.ofNullable(payOrder).map(o-> o.getOverTime()).orElse(null);
    }

    @ApiModelProperty(value="支付成功时间")
    @JSONField(serializeUsing = TimestampSerializer.class, deserializeUsing = TimestampDeserializer.class)
    public Timestamp getSuccessTime() {
        return Optional.ofNullable(payOrder).map(o-> o.getSuccessTime()).orElse(null);
    }

    @ApiModelProperty(value="取消时间")
    @JSONField(serializeUsing = TimestampSerializer.class, deserializeUsing = TimestampDeserializer.class)
    public Timestamp getCancelTime() {
        return Optional.ofNullable(payOrder).map(o-> o.getCancelTime()).orElse(null);
    }

    @ApiModelProperty(value="退款标记")
    @JSONField(serializeUsing = IntegerSerializer.class, deserializeUsing = IntegerDeserializer.class)
    public Integer getIsBack() {
        return Optional.ofNullable(payOrder).map(o-> o.getIsBack()).orElse(null);
    }

    @ApiModelProperty(value="支付备注")
    public String getPayRemark() {
        return Optional.ofNullable(payOrder).map(o-> o.getPayRemark()).map(o-> o.trim())
                .filter(o-> !o.equals("")).orElse(null);
    }
}
